define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'campus_class/index' + location.search,
                    add_url: 'campus_class/add',
                    edit_url: 'campus_class/edit',
                    del_url: 'campus_class/del',
                    multi_url: 'campus_class/multi',
                    import_url: 'campus_class/import',
                    table: 'campus_class',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'campuscoursemanagement.name', title: __('Campuscoursemanagement.name'), operate: 'LIKE'},
                        {field: 'class_name', title: __('Teacher_id'), operate: 'FIND_IN_SET'},
                        {field: 'class_hour', title: __('Class_hour')},
                        {field: '', title: __('人数/容量'),
                            formatter: function(row,data){
                                console.log(row,data)
                                let html = '<div>'+data.num+'/'+data.class_size+'</div>'
                                //`<span class="icon-open">+</span>${data.goodsspec.length}项`
                                return html
                            }},
                        {field: '', title: __('已上/排课课次'),
                            formatter: function(row,data){
                                console.log(row,data)
                                let html = '<div>'+data.has_course_schedule+'/'+data.course_schedule+'</div>'
                                //`<span class="icon-open">+</span>${data.goodsspec.length}项`
                                return html
                            }},
                        {field: 'campusclasscategory.name', title: __('Class_id')},
                        {
                            field: 'operate',
                            // width: "120px",
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('班级详情'),
                                    title: __('班级详情'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-dialog',
                                    // icon: 'fa fa-magic',
                                    url: 'campus_class_course_arranging/index/ids/{ids}',
                                    extend: 'data-area=["100%","100%"]',
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $(document).on('click','#class_set' ,function (e) {
                console.log( $(this).data('id'))
                Layer.open({
                    type: 2,
                    content:'/manystore/campus_class_category/index',
                    area:['50%','60%'],
                    //content: Config.url
                })
            })
            $(document).on('click','#classroom_set' ,function (e) {
                console.log( $(this).data('id'))
                Layer.open({
                    type: 2,
                    content:'/manystore/campus_classroom/index',
                    area:['50%','60%'],
                    //content: Config.url
                })
            })
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});